package com.fastCms.manager.frame.controller;


import com.fastCms.business.frame.busi.ValidateManageService;
import com.fastCms.business.frame.pojo.po.ValidateCodeCheckPO;
import com.fastCms.business.frame.pojo.po.ValidateCodeSendPO;
import com.fastCms.business.frame.response.ApiResponse;
import com.fastCms.business.frame.response.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 验证码
 */
@RestController
@RequestMapping("/validate")
@Api(value = "ValidateController", tags = "后端-验证管理")
@Validated
public class ValidateController {
    @Autowired
    private ValidateManageService validateManageServiceImpl;

    /**
     * 获取验证码
     *
     * @param response
     * @throws Exception
     */
    @GetMapping("/getPicValidateCode")
    @ApiOperation(value = "图片-获取验证码", notes = "图片-数字验证码")
    public ApiResponse<String> getPicValidateCode(HttpServletResponse response, HttpServletRequest request) throws Exception {
        String validateCode = validateManageServiceImpl.getPicValidateCode(response, request);
        return ResponseUtil.success(validateCode);
    }

    /**
     * 校验验证码
     *
     * @return
     */
    @GetMapping("/checkPicValidateCode")
    @ApiOperation(value = "图片-校验验证码", notes = "图片-数字验证码校验")
    public ApiResponse picCheckCode(HttpServletRequest request, @RequestParam(value = "validCode", required = true) String validCode) {
        ApiResponse<Boolean> result = validateManageServiceImpl.checkPicValidateCode(request, validCode);
        return result;
    }

    /**
     * 短信-验证码
     *
     * @return
     */
    @GetMapping("/sendSmsValidateCode")
    @ApiOperation(value = "短信-发送验证码", notes = "图片-发送验证码校验")
    public ApiResponse smsSendCode(@RequestBody ValidateCodeSendPO param) {
        ApiResponse<Boolean> result = validateManageServiceImpl.smsSendValidateCode(param);
        return result;
    }

    /**
     * 短信-校验验证码
     *
     * @return
     */
    @GetMapping("/checkSmsValidateCode")
    @ApiOperation(value = "短信-校验验证码", notes = "图片-数字验证码校验")
    public ApiResponse checkSmsValidateCode(@RequestBody ValidateCodeCheckPO param) {
        ApiResponse<Boolean> result = validateManageServiceImpl.checkSmsValidateCode(param);
        return result;
    }

}

